<template>
  <div class="list-table">
    <div class="area-header">
      <span class="area-header-title">{{ $t('投资收益情况(个人)') }}</span>
    </div>
    <el-form ref="queryForm" :model="queryParams" :inline="true">
      <el-form-item :label="$t('统计类型')" prop="countType">
        <el-select v-model="queryParams.countType" :placeholder="$t('统计类型')">
          <el-option
            v-for="dict in statusOptions"
            :key="dict.dictValue"
            :label="$t(dict.dictLabel)"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item :label="$t('姓名')" prop="userIdList">
        <UserSelect v-model="queryParams.userIdList" :multiple="true" :placeholder="$t('姓名')" />
      </el-form-item>
      <el-form-item :label="$t('团队')" prop="deptIdList">
        <DeptSelect v-model="queryParams.deptIdList" multiple :placeholder="$t('团队')" check-strictly="true" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="queryHandle">{{ $t("搜索") }}</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">{{ $t("重置") }}</el-button>
      </el-form-item>
    </el-form>

    <el-row v-loading="loading" :gutter="10">
      <el-table :data="list" tooltip-effect="darkTable" :default-sort="{prop: 'date', order: 'descending'}" border>
        <el-table-column :label="$t('序号')" type="index" align="center" show-overflow-tooltip width="50">
          <template slot-scope="scope">
            {{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}
          </template>
        </el-table-column>
        <el-table-column :label="$t('姓名')" align="center" prop="userName" show-overflow-tooltip width="100" />
        <el-table-column :label="$t('团队')" align="center" prop="deptName" show-overflow-tooltip width="120" />
        <el-table-column :label="$t('投资项目个数')" align="center">
          <el-table-column :label="$t(firstYear)" align="center" prop="dealCountFirst" sortable show-overflow-tooltip>
            <template slot-scope="scope">
              <span class="link-type" @click="updateHandle(scope.row, firstYear)">{{ scope.row.dealCountFirst }}</span>
            </template>
          </el-table-column>
          <el-table-column :label="$t(secondYear)" align="center" prop="dealCountSecond" sortable show-overflow-tooltip>
            <template slot-scope="scope">
              <span class="link-type" @click="updateHandle(scope.row, secondYear)">{{ scope.row.dealCountSecond }}</span>
            </template>
          </el-table-column>
          <el-table-column :label="$t(thirdYear)" align="center" prop="dealCountThird" sortable show-overflow-tooltip>
            <template slot-scope="scope">
              <span class="link-type" @click="updateHandle(scope.row, thirdYear)">{{ scope.row.dealCountThird }}</span>
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column :label="$t('投资规模') + $t('金额单位')" align="center">
          <el-table-column :label="$t(firstYear)" align="center" prop="investFirst" width="120" sortable show-overflow-tooltip>
            <template slot-scope="scope">
              <span class="money-text">{{ moneyFormat(scope.row.investFirst, 'w') }}</span>
            </template>
          </el-table-column>
          <el-table-column :label="$t(secondYear)" align="center" prop="investSecond" width="120" sortable show-overflow-tooltip>
            <template slot-scope="scope">
              <span class="money-text">{{ moneyFormat(scope.row.investSecond, 'w') }}</span>
            </template>
          </el-table-column>
          <el-table-column :label="$t(thirdYear)" align="center" prop="investThird" width="120" sortable show-overflow-tooltip>
            <template slot-scope="scope">
              <span class="money-text">{{ moneyFormat(scope.row.investThird, 'w') }}</span>
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column :label="$t('回款规模') + $t('金额单位')" align="center">
          <el-table-column :label="$t(firstYear)" align="center" prop="hkFirst" width="120" sortable show-overflow-tooltip>
            <template slot-scope="scope">
              <span class="money-text">{{ moneyFormat(scope.row.hkFirst, 'w') }}</span>
            </template>
          </el-table-column>
          <el-table-column :label="$t(secondYear)" align="center" prop="hkSecond" width="120" sortable show-overflow-tooltip>
            <template slot-scope="scope">
              <span class="money-text">{{ moneyFormat(scope.row.hkSecond, 'w') }}</span>
            </template>
          </el-table-column>
          <el-table-column :label="$t(thirdYear)" align="center" prop="hkThird" width="120" sortable show-overflow-tooltip>
            <template slot-scope="scope">
              <span class="money-text">{{ moneyFormat(scope.row.hkThird, 'w') }}</span>
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column :label="$t('估值规模') + $t('金额单位')" align="center">
          <el-table-column :label="$t(firstYear)" align="center" prop="gzFirst" width="120" sortable show-overflow-tooltip>
            <template slot-scope="scope">
              <span class="money-text">{{ moneyFormat(scope.row.gzFirst, 'w') }}</span>
            </template>
          </el-table-column>
          <el-table-column :label="$t(secondYear)" align="center" prop="gzSecond" width="120" sortable show-overflow-tooltip>
            <template slot-scope="scope">
              <span class="money-text">{{ moneyFormat(scope.row.gzSecond, 'w') }}</span>
            </template>
          </el-table-column>
          <el-table-column :label="$t(thirdYear)" align="center" prop="gzThird" width="120" sortable show-overflow-tooltip>
            <template slot-scope="scope">
              <span class="money-text">{{ moneyFormat(scope.row.gzThird, 'w') }}</span>
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column :label="$t('回报倍数')" align="center">
          <el-table-column :label="$t(firstYear)" align="center" prop="hbFirst" width="120" sortable show-overflow-tooltip>
            <template slot-scope="scope">
              <span class="money-text">{{ moneyFormat(scope.row.hbFirst) }}</span>
            </template>
          </el-table-column>
          <el-table-column :label="$t(secondYear)" align="center" prop="hbSecond" width="120" sortable show-overflow-tooltip>
            <template slot-scope="scope">
              <span class="money-text">{{ moneyFormat(scope.row.hbSecond) }}</span>
            </template>
          </el-table-column>
          <el-table-column :label="$t(thirdYear)" align="center" prop="hbThird" width="120" sortable show-overflow-tooltip>
            <template slot-scope="scope">
              <span class="money-text">{{ moneyFormat(scope.row.hbThird) }}</span>
            </template>
          </el-table-column>
        </el-table-column>
      </el-table>
    </el-row>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 用户投资项目明细 -->
    <el-dialog :title="$t('项目投资明细')" :visible.sync="formOpen" :close-on-click-modal="false" :lock-scroll="false" :destroy-on-close="true" append-to-body custom-class="dialogView">
      <investIncomePersonList ref="investIncomePersonList" :user-id="userId" :count-type="countType" :year="year" />
    </el-dialog>
  </div>
</template>

<script>
import { investIncomePerson } from '@/api/base/deal/dealBase'
import investIncomePersonList from '@/views/deal/report/investIncomePersonList'
export default {
  components: {
    investIncomePersonList
  },
  data() {
      return {
          list: [],
          loading: false,
          formOpen: false,
          total: 0,
           // 统计类型（负责项目：fzxm，参与项目:cyxm）
          statusOptions: [
            { dictValue: 'fzxm', dictLabel: '负责项目' },
            { dictValue: 'cyxm', dictLabel: '参与项目' }
          ],
          queryParams: {
            countType: 'fzxm',
            userIdList: [],
            deptIdList: [],
            pageNum: 1,
            pageSize: 10
          },
          form: {},
          countType: undefined,
          userId: undefined,
          year: undefined,
          // 今年 例如今年2023 这里就是 '2023'
          thirdYear: undefined,
          // 去年 例如今年2023 这里就是 '2022'
          secondYear: undefined,
          // 前年 例如今年2023 这里就是 '2021'
          firstYear: undefined,
          rules: {
          }
      }
  },
  mounted() {
  },
  created() {
    this.getCurrentThreeYear()
    this.getList()
  },
  methods: {
    getList() {
      this.loading = true
      investIncomePerson(this.queryParams).then(response => {
        this.list = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    /** 修改按钮操作 */
    updateHandle(row, year) {
      this.formOpen = true
      this.countType = this.queryParams.countType
      this.userId = row.userId
      this.year = year
      this.$nextTick(() => {
        this.$refs.investIncomePersonList.getList()
      })
    },
    // 排序
    sortNumber(a, b) {
      return a.total - b.total
    },
    // 获取最近三年的年份，用于显示label
    getCurrentThreeYear() {
      var date = new Date()
      this.thirdYear = date.getFullYear()
      console.log('thirdYear', this.thirdYear)
      this.secondYear = date.getFullYear() - 1
      console.log('secondYear', this.secondYear)
      this.firstYear = date.getFullYear() - 2
      console.log('firstYear', this.firstYear)
    },
    // 表单重置
    reset() {
        this.form = {
            id: undefined
        }
        this.resetForm('form')
    },
    /** 搜索按钮操作 */
    queryHandle() {
        this.queryParams.pageNum = 1
        this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
        this.resetForm('queryForm')
        this.queryHandle()
    }
  }
}
</script>
